﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using SectionSignAndFilled.StairsRoomPlanSign.ModelLayer;

namespace SectionSignAndFilled.StairsRoomPlanSign.ControlLayer
{
	public class StairsSignManger : IDimensionPrepare, IDimensionMake
	{
		public StairsSignManger(StairPlanDataPacker inputPlanData)
		{
			this.m_useStairPlanData = inputPlanData;
			this.m_useViewData = this.m_useStairPlanData.UseViewData;
			foreach (string value in Enum.GetNames(typeof(StairsDimensionKindEnum)))
			{
				this.m_dicAllDic.Add((StairsDimensionKindEnum)Enum.Parse(typeof(StairsDimensionKindEnum), value), new List<IDimensionMake>());
				this.m_lstAllStairsDimensionKind.Add((StairsDimensionKindEnum)Enum.Parse(typeof(StairsDimensionKindEnum), value));
			}
		}

		public void PrepareDimension()
		{
			this.m_StairsPacker = this.GetAllStairsPacker();
			List<IDimensionMake> collection = new List<IDimensionMake>();
			if (this.m_useGeterFactory.TryGetADimensionPackerGeter(this.m_StairsPacker, out this.m_useDimensionPackerGeter))
			{
				foreach (StairsDimensionKindEnum stairsDimensionKindEnum in this.m_lstAllStairsDimensionKind)
				{
					if (this.m_useDimensionPackerGeter.TryGetADimensionBean(this.m_StairsPacker, stairsDimensionKindEnum, out collection))
					{
						this.m_dicAllDic[stairsDimensionKindEnum].AddRange(collection);
					}
				}
			}
		}

		public bool TryMakeSign(Document inputDoc, ViewPlan useView)
		{
			bool result = true;
			foreach (KeyValuePair<StairsDimensionKindEnum, List<IDimensionMake>> keyValuePair in this.m_dicAllDic)
			{
				foreach (IDimensionMake dimensionMake in keyValuePair.Value)
				{
					dimensionMake.TryMakeSign(inputDoc, useView);
				}
			}
			return result;
		}

		private SignUseStairsPacker GetAllStairsPacker()
		{
			List<Stairs> list = new List<Stairs>();
			foreach (KeyValuePair<Stairs, int> keyValuePair in this.m_useStairPlanData.LstStairs)
			{
				list.Add(keyValuePair.Key);
			}
			return new SignUseStairsPacker(this.m_useStairPlanData, this.m_useStairPlanData.LstSameLevelStairsPacker);
		}

		private Dictionary<StairsDimensionKindEnum, List<IDimensionMake>> m_dicAllDic = new Dictionary<StairsDimensionKindEnum, List<IDimensionMake>>();

		private List<StairsDimensionKindEnum> m_lstAllStairsDimensionKind = new List<StairsDimensionKindEnum>();

		private StairPlanDataPacker m_useStairPlanData;

		private ViewData m_useViewData;

		private SignUseStairsPacker m_StairsPacker;

		private IStairsDimensionPackerGeter m_useDimensionPackerGeter;

		private StairsDimensionPackerGeterFactory m_useGeterFactory = StairsDimensionPackerGeterFactory.GetFactory();
	}
}
